package com.prd.controller;

import com.prd.constant.CheckStatus;
import com.prd.model.EntBudget;
import com.prd.model.EntBudgetCheck;
import com.prd.model.EntGoal;
import com.prd.model.EntGoalCoach;
import com.prd.service.EntBudgetCheckService;
import com.prd.service.EntBudgetCourseService;
import com.prd.service.EntBudgetService;
import com.prd.util.AjaxResult;
import com.prd.util.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = {"预决算管理"})
@RestController
@RequestMapping("/api/entBudget")
public class EntBudgetController extends BaseController {

    @Autowired
    private EntBudgetService entBudgetService;

    @Autowired
    private EntBudgetCheckService entBudgetCheckService;

    @ApiOperation("查询列表")
    @GetMapping("list")
    public TableDataInfo list(@ApiParam("日期") String day, @ApiParam("0：全部、1：草稿、2：待审批、3：不通过、4：执行中、5：执行完成") Integer catalog) {
        startPage();
        List<EntBudget> list = entBudgetService.listInfo(day, catalog);
        return getDataPage(list);
    }

    @ApiOperation("添加信息")
    @PostMapping("add")
    public AjaxResult add(@RequestBody EntBudget entBudget) {
        return toAjax(entBudgetService.saveOrUpdateInfo(entBudget, true));
    }

    @ApiOperation("修改信息")
    @PostMapping("update")
    public AjaxResult update(@RequestBody EntBudget entBudget) {
        return toAjax(entBudgetService.saveOrUpdateInfo(entBudget, false));
    }

    @ApiOperation("查询详情")
    @GetMapping("details/{id}")
    public AjaxResult details(@PathVariable("id") Long id) {
        return AjaxResult.success(entBudgetService.details(id));
    }

    @ApiOperation("申请审核")
    @PostMapping("applyAudit/{id}")
    public AjaxResult applyAudit(@PathVariable("id") Long id) {
        return toAjax(entBudgetService.applyAudit(id));
    }

    @ApiOperation("审核通过")
    @PostMapping("pass")
    public AjaxResult pass(@RequestBody EntBudgetCheck entBudgetCheck) {
        entBudgetCheck.setType(CheckStatus.TWO.getCode());
        return toAjax(entBudgetService.pass(entBudgetCheck));
    }

    @ApiOperation("审核不通过")
    @PostMapping("notPass")
    public AjaxResult notPass(@RequestBody EntBudgetCheck entBudgetCheck) {
        entBudgetCheck.setType(CheckStatus.THREE.getCode());
        return toAjax(entBudgetService.pass(entBudgetCheck));
    }

    @ApiOperation("增加抄送人")
    @PostMapping(value = "addMake/{budgetId}/{makes}")
    public AjaxResult addMake(@ApiParam("预算ID") @PathVariable("budgetId") Long budgetId, @ApiParam("抄送人（多个,分开）") @PathVariable("makes") Long[] makes) {
        return toAjax(entBudgetService.addMake(budgetId, makes));
    }

    @ApiOperation("查询人员权限")
    @GetMapping("jurisdiction/{budgetId}")
    public AjaxResult jurisdiction(@PathVariable("budgetId") Long budgetId) {
        return AjaxResult.success(entBudgetService.jurisdiction(budgetId));
    }

    @ApiOperation("添加决算意见")
    @PostMapping("addOpinion")
    public AjaxResult addOpinion(@RequestBody EntBudgetCheck entBudgetCheck) {
        return toAjax(entBudgetCheckService.insertInfo(entBudgetCheck));
    }

    @ApiOperation("添加预决算汇总报告")
    @PostMapping("addSummaryReport")
    public AjaxResult addSummaryReport(@RequestBody EntBudgetCheck entBudgetCheck) {
        return toAjax(entBudgetCheckService.insertInfo(entBudgetCheck));
    }
}
